package com.clstu.method;

public class ThreadMethod {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.setName("阿龙");//设置线程名
        t.setPriority(Thread.MIN_PRIORITY);//设置优先级
        System.out.println(t.getName());//获取线程明
        System.out.println(t.getPriority());//获取优先级
        t.start();
        for (int i = 0; i < 5; i++) {
            System.out.println("hi    "+i);
            Thread.sleep(1000);
        }
        t.interrupt();//中断子线程的休眠，产生一个中断异常InterruptedException

    }
}
class T extends Thread{
    @Override
    public void run() {
        while (true) {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + "  吃包子~~~~" + i);
            }
            try {
                System.out.println(Thread.currentThread().getName() + "   休眠中~~~~~~~~");
                Thread.sleep(10 * 1000);//休息10s继承吃，这期间被中断interrupt之后会进入catch执行，提前结束休眠
            } catch (InterruptedException e) {
                e.printStackTrace();
                System.out.println(Thread.currentThread().getName()+"  被interrupt掉了~~~~");
//                break;
            }
        }
    }
}